package com.yanqu.road.server.cmd.variety;

import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.variety.VarietyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.match.CrossMatchMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;

/**
 * @author ：zfr
 * @date ：2021/2/23 16:00
 */
@Cmd(code = CrossProtocol.C_VARIETY_SYNC_VARIETY_RED_POT, desc = "同步红点")
public class SyncVarietyRedPotCrossCmd extends CrossCommand {
    private VarietyProto.VarietyRedPot.Builder respMsg;
    private long playerId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        respMsg = VarietyProto.VarietyRedPot.parseFrom(packet.getBytes()).toBuilder();
        playerId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossMatchMgr.syncRedPot(serverId, playerId, respMsg);
    }

    @Override
    public void sendData() {
        YanQuMessage message = YanQuMessageUtils.buildMessage(ClientProtocol.U_VARIETY_SYNC_RED_POT, respMsg);
        MessageHelper.sendPacket(serverId, playerId, message);
    }
}
